// pages/personal/myorder/returnRefund/returnRefund.js
import { queryList } from '../../../../../config/config'
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: getApp().globalData.imgUrl,
    page: 1,
    rows: 10,
    refundData: false,
    refundData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  // 获取退款列表
  getRefund() {
    let that = this
    let params = {
      page: that.data.page,
      rows: that.data.rows
    }
    // let listParams = JSON.stringify(params)
    app.reqFun.requestForm('POST',queryList,params,(res)=>{
      if(res.data.success === 1) {
        let records = res.data.data.records
        if (records) {
          let refundTypelist = app.globalData.getListvalue(app.globalData.valLsit, 'REFUND_TYPE')
          res.data.data.records[0].skuSpecs = JSON.parse(res.data.data.records[0].skuSpecs)
          for(var i = 0, len = res.data.data.records.length; i < len; i++) {
            let type = this.filterByName(refundTypelist, res.data.data.records[i].refundType)
            res.data.data.records[i].refundName = type[0].name
          }
          if ( that.data.rows*that.data.page >= res.data.data.total) {
            that.setData({
              nomoreData: true
            })
          }
          that.setData({
            refundData: that.data.refundData.concat(records)
          })
          // this.setData({
          //   refundData: res.data.data.records
          // })
        }
      }
    })
  },
  filterByName(aim, name) {
    return aim.filter(item => item.val == name)
  },
  refundDetail(e) {
    let data = e.currentTarget.dataset.data
    wx.navigateTo({
      url: '../refundDetail/refundDetail?id=' + data.id
    })
  },
  goreBack(e){
   wx.redirectTo({
    url: '/packagMy/pages/personal/index/index'
   })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      page: 1,
      rows: 10,
      refundData: false,
      refundData: []
    })
    this.getRefund()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomoreData) {
      this.setData({
        page: this.data.page + 1
      })
      this.getRefund()
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})